package com.example.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

import javax.websocket.server.ServerEndpointConfig;

/**
 * WebSocket配置
 * @Author: 不是菜鸡爱编程
 * @Date: 2023/12/31/21:44
 * @Description:
 */
@Configuration
public class WebSocketConfig extends ServerEndpointConfig.Configurator {

    //@Override
    //public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
    //
    //    //获取httpsession
    //    HttpSession session = (HttpSession) request.getHttpSession();
    //    sec.getUserProperties().put(HttpSession.class.getName(), session);
    //}

    /**
     * 注入一个ServerEndpointExporter
     * 该Bean会自动注册使用@ServerEndpoint注解声明的websocket endpoint
     * @return {@link ServerEndpointExporter}
     */
    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }

}